package com.dianping.cat.configuration.server.transform;

import com.dianping.cat.configuration.server.entity.ConsumerConfig;
import com.dianping.cat.configuration.server.entity.Domain;
import com.dianping.cat.configuration.server.entity.HarfsConfig;
import com.dianping.cat.configuration.server.entity.HdfsConfig;
import com.dianping.cat.configuration.server.entity.LongConfig;
import com.dianping.cat.configuration.server.entity.Property;
import com.dianping.cat.configuration.server.entity.Server;
import com.dianping.cat.configuration.server.entity.ServerConfig;
import com.dianping.cat.configuration.server.entity.StorageConfig;
import org.xml.sax.Attributes;





















public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
/*  38 */   public ConsumerConfig buildConsumer(Attributes attributes) { return new ConsumerConfig(); }




  
  public Domain buildDomain(Attributes attributes) {
/*  45 */     String name = attributes.getValue("name");
/*  46 */     String urlThreshold = attributes.getValue("url-threshold");
/*  47 */     String sqlThreshold = attributes.getValue("sql-threshold");
/*  48 */     String serviceThreshold = attributes.getValue("service-threshold");
/*  49 */     Domain domain = new Domain(name);

/*  51 */     if (urlThreshold != null) {
/*  52 */       domain.setUrlThreshold((Integer)convert(Integer.class, urlThreshold, null));
    }
    
/*  55 */     if (sqlThreshold != null) {
/*  56 */       domain.setSqlThreshold((Integer)convert(Integer.class, sqlThreshold, null));
    }
    
/*  59 */     if (serviceThreshold != null) {
/*  60 */       domain.setServiceThreshold((Integer)convert(Integer.class, serviceThreshold, null));
    }
    
/*  63 */     return domain;
  }

  
  public HarfsConfig buildHarfs(Attributes attributes) {
/*  68 */     String id = attributes.getValue("id");
/*  69 */     String maxSize = attributes.getValue("max-size");
/*  70 */     String serverUri = attributes.getValue("server-uri");
/*  71 */     String baseDir = attributes.getValue("base-dir");
/*  72 */     HarfsConfig harfs = new HarfsConfig(id);

/*  74 */     if (maxSize != null) {
/*  75 */       harfs.setMaxSize(maxSize);
    }
    
    if (serverUri != null) {
/*  79 */       harfs.setServerUri(serverUri);
    }
    
/*  82 */     if (baseDir != null) {
/*  83 */       harfs.setBaseDir(baseDir);
    }
    
/*  86 */     return harfs;
  }

  
  public HdfsConfig buildHdfs(Attributes attributes) {
/*  91 */     String id = attributes.getValue("id");
/*  92 */     String maxSize = attributes.getValue("max-size");
/*  93 */     String serverUri = attributes.getValue("server-uri");
/*  94 */     String baseDir = attributes.getValue("base-dir");
/*  95 */     HdfsConfig hdfs = new HdfsConfig(id);

/*  97 */     if (maxSize != null) {
/*  98 */       hdfs.setMaxSize(maxSize);
    }
    
/* 101 */     if (serverUri != null) {
/* 102 */       hdfs.setServerUri(serverUri);
    }
    
/* 105 */     if (baseDir != null) {
/* 106 */       hdfs.setBaseDir(baseDir);
    }
    
/* 109 */     return hdfs;
  }

  
  public LongConfig buildLongConfig(Attributes attributes) {
/* 114 */     String defaultUrlThreshold = attributes.getValue("default-url-threshold");
/* 115 */     String defaultSqlThreshold = attributes.getValue("default-sql-threshold");
/* 116 */     String defaultServiceThreshold = attributes.getValue("default-service-threshold");
/* 117 */     LongConfig longConfig = new LongConfig();

/* 119 */     if (defaultUrlThreshold != null) {
/* 120 */       longConfig.setDefaultUrlThreshold(((Integer)convert(Integer.class, defaultUrlThreshold, Integer.valueOf(0))).intValue());
    }
    
/* 123 */     if (defaultSqlThreshold != null) {
/* 124 */       longConfig.setDefaultSqlThreshold(((Integer)convert(Integer.class, defaultSqlThreshold, Integer.valueOf(0))).intValue());
    }
    
/* 127 */     if (defaultServiceThreshold != null) {
/* 128 */       longConfig.setDefaultServiceThreshold(((Integer)convert(Integer.class, defaultServiceThreshold, Integer.valueOf(0))).intValue());
    }
    
/* 131 */     return longConfig;
  }

  
  public Property buildProperty(Attributes attributes) {
/* 136 */     String name = attributes.getValue("name");
/* 137 */     String value = attributes.getValue("value");
/* 138 */     Property property = new Property(name);

/* 140 */     if (value != null) {
/* 141 */       property.setValue(value);
    }
    
/* 144 */     return property;
  }

  
  public Server buildServer(Attributes attributes) {
/* 149 */     String id = attributes.getValue("id");
/* 150 */     return new Server(id);
  }




  
/* 157 */   public ServerConfig buildServerConfig(Attributes attributes) { return new ServerConfig(); }




  
  public StorageConfig buildStorage(Attributes attributes) {
/* 164 */     String localBaseDir = attributes.getValue("local-base-dir");
/* 165 */     String maxHdfsStorageTime = attributes.getValue("max-hdfs-storage-time");
/* 166 */     String localReportStorageTime = attributes.getValue("local-report-storage-time");
/* 167 */     String localLogivewStorageTime = attributes.getValue("local-logivew-storage-time");
/* 168 */     String harMode = attributes.getValue("har-mode");
/* 169 */     String uploadThread = attributes.getValue("upload-thread");
/* 170 */     StorageConfig storage = new StorageConfig();

/* 172 */     if (localBaseDir != null) {
/* 173 */       storage.setLocalBaseDir(localBaseDir);
    }
    
/* 176 */     if (maxHdfsStorageTime != null) {
/* 177 */       storage.setMaxHdfsStorageTime(((Integer)convert(Integer.class, maxHdfsStorageTime, Integer.valueOf(0))).intValue());
    }
    
/* 180 */     if (localReportStorageTime != null) {
/* 181 */       storage.setLocalReportStorageTime(((Integer)convert(Integer.class, localReportStorageTime, Integer.valueOf(0))).intValue());
    }
    
/* 184 */     if (localLogivewStorageTime != null) {
/* 185 */       storage.setLocalLogivewStorageTime(((Integer)convert(Integer.class, localLogivewStorageTime, Integer.valueOf(0))).intValue());
    }
    
/* 188 */     if (harMode != null) {
/* 189 */       storage.setHarMode(((Boolean)convert(Boolean.class, harMode, Boolean.valueOf(false))).booleanValue());
    }
    
/* 192 */     if (uploadThread != null) {
/* 193 */       storage.setUploadThread(((Integer)convert(Integer.class, uploadThread, Integer.valueOf(0))).intValue());
    }
    
/* 196 */     return storage;
  }

  
  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 201 */     if (value == null || value.length() == 0) {
/* 202 */       return defaultValue;
    }
    
/* 205 */     if (type == Boolean.class || type == boolean.class)
/* 206 */       return (T)Boolean.valueOf(value); 
/* 207 */     if (type == Integer.class || type == int.class)
/* 208 */       return (T)Integer.valueOf(value); 
/* 209 */     if (type == Long.class || type == long.class)
/* 210 */       return (T)Long.valueOf(value); 
/* 211 */     if (type == Short.class || type == short.class)
/* 212 */       return (T)Short.valueOf(value); 
/* 213 */     if (type == Float.class || type == float.class)
/* 214 */       return (T)Float.valueOf(value); 
/* 215 */     if (type == Double.class || type == double.class)
/* 216 */       return (T)Double.valueOf(value); 
/* 217 */     if (type == Byte.class || type == byte.class)
/* 218 */       return (T)Byte.valueOf(value); 
/* 219 */     if (type == Character.class || type == char.class) {
/* 220 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 222 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-core-3.0.0.jar!/com/dianping/cat/configuration/server/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */